@node I/O extensions
@section I/O extensions

@stindex extended-ports
These facilities are all exported from the @code{extended-ports}
structure.

@cindex ports with line & column numbers
@cindex line- & column-tracking ports
@cindex ports that track line & column numbers
Tracking ports track the line & column number that they are on.

@deffn procedure make-tracking-input-port sub-port @returns{} input-port
@deffnx procedure make-tracking-output-port sub-port @returns{} output-port
Tracking port constructors.  These simply create wrapper ports around
@var{sub-port} that track the line & column numbers.
@end deffn

@deffn procedure current-row port @returns{} integer or @code{#f}
@deffnx procedure current-column port @returns{} integer or @code{#f}
Accessors for line (row) & column number information.  If @var{port} is
a not a tracking port, these simply return @code{#f}.
@end deffn

@deffn procedure fresh-line port @returns{} unspecified
This writes a newline to port with @code{newline}, unless it can be
determined that the previous character was a newline --- that is, if
@code{(current-column @var{port})} does not evaluate to zero.
@end deffn

@cindex character source input ports
@cindex character sink output ports
@cindex simple character source input ports
@cindex simple character sink output ports
These are ports based on procedures that produce and consume single
characters at a time.

@deffn procedure char-source->input-port char-producer [readiness-tester closer] @returns{} input-port
@deffnx procedure char-sink->output-port char-consumer @returns{} output-port
@code{Char-source->input-port} creates an input port that calls
@var{char-producer} with zero arguments when a character is read from
it.  If @var{readiness-tester} is present, it is used for the
@code{char-ready?} operation on the resulting port; likewise with
@var{closer} and @code{close-input-port}.
@code{Char-sink->output-port} creates an output port that calls
@var{char-consumer} for every character written to it.
@end deffn

@cindex string ports
@cindex string input ports
@cindex string output ports
@cindex input ports from strings
@cindex output ports to strings
Scheme48 also provides ports that collect and produce output to and
from strings.

@deffn procedure make-string-input-port string @returns{} input-port
Constructs an input port whose contents are read from @var{string}.
@end deffn

@deffn procedure make-string-output-port @returns{} output-port
@deffnx procedure string-output-port-output string-port @returns{} string
@deffnx procedure call-with-string-output-port receiver @returns{} string
@code{Make-string-output-port} makes an output port that collects its
output in a string.  @code{String-output-port-output} returns the
string that @var{string-port} collected.
@code{Call-with-string-output-port} creates a string output port,
applies @var{receiver} to it, and returns the string that the string
output port collected.
@end deffn

@cindex limiting output
Finally, there is a facility for writing only a limited quantity of
output to a given port.

@deffn procedure limit-output port count receiver @returns{} unspecified
@code{Limit-output} applies @var{receiver} to a port that will write at
most @var{count} characters to @var{port}.
@end deffn
